import Vue from "vue";
import App from "./App.vue";
import router from "./router";
import store from "./store";

Vue.config.productionTip = false;

//1.导入axios的对象
import axios from "@/utils/request.js";
//2.把axios加入vue的原型中去，方便访问
Vue.prototype.$axios = axios;

// 引入element-ui
import ElementUI from "element-ui";
import "element-ui/lib/theme-chalk/index.css";
Vue.use(ElementUI);

//引入echarts
import * as echarts from 'echarts';
Vue.prototype.$echarts = echarts;

//全局引入vue-quill-editor中引入
import VueQuillEditor from 'vue-quill-editor'
Vue.use(VueQuillEditor)

//全局路由守卫
router.beforeEach((to, from, next) => {
  // 获取本地存储存的token值
  let token = sessionStorage.getItem("03B_user");
  // 判断当前是否是登录页面
  if (to.path == "/admin/login") {
    // 用户登录直接跳转到管理后台首页
    token != null ? next("/admin/home") : "";
  } else {
    // 管理后台页面，用户如果没有登录的话，返回登录页面即可
    token == null ? next("/admin/login") : "";
  }

  store.commit("addBread", {
    title: to.meta.title,
    url: to.path
  })
  next();
});

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount("#app");